<?php
/**
 * @orm tablename meter_readings
 * @orm listener afterInsert afterInsert
 */
class MeterReading extends DomArObject {
	/**
	 * @orm plugin DomArDateTime(now)
	 */
	public $datetime;
	/**
	 * @orm float(12,3)
	 */
	public $reading;
	/**
	 * @orm bool
	 */
	public $isSent = false;
	/**
	 * @orm char(20)
	 */
	public $clientID;
	/**
	 * @orm char(20)
	 */
	public $electricitySupplier;
	/**
	 * @orm has parent Client inverse meterReadings
	 */
	public $client;
	const ONE_KILO_WATT_PRICE = 0.5;

	public function afterInsert() {
		$ch = curl_init( 'http://esi.vels.dev.modera.net/project/service/rest_server.php?message=meterReading&clientId='.$this->client->username.'&esId='.$this->electricitySupplier.'&reading='.$this->reading );
		curl_setopt( $ch, CURLOPT_HEADER, 0 );
		curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
		$result = curl_exec( $ch );
		curl_close( $ch );
	}

}
?>